package controller;

import java.io.IOException;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import DAO.BookDetailsDAO;
import DAO.DAOFactory;
import DAO.NotFoundException;

import model.BookDetailsDTO;

@WebServlet("/MakeABookingProceed")
public class MakeABookingProceed extends HttpServlet {
	private static final long serialVersionUID = 1L;
    	
    public MakeABookingProceed() {
        super();
    }

	protected void doGet(HttpServletRequest request, HttpServletResponse response) 
			throws ServletException, IOException {
		  doProcess(request, response) ;
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) 
			throws ServletException, IOException {
		doProcess(request, response) ;
	}
	
	protected void doProcess(HttpServletRequest request, HttpServletResponse response) 
			throws ServletException, IOException {
		
		SimpleDateFormat df=new SimpleDateFormat("yyyy-MM-dd");
		String fromDate=request.getParameter("fromDate");
		if(fromDate=="")
		{
			fromDate=df.format(new Date());
			System.out.println("new"+fromDate);
		}
		String toDate=request.getParameter("toDate");
		if(toDate=="")
		{
			toDate=df.format(new Date());
		}

		String type=request.getParameter("type");
		String emergency;
		if(request.getParameter("emergency")!=null)
		{
			emergency="Y";
		}
		else{
			emergency="N";
		}

		String priority = request.getParameter("priority");
		String priorityDisplay;
		if (priority.equals("1")){
			priorityDisplay="High";
		}
		else if (priority.equals("2"))
		{
			priorityDisplay="Medium";
		}
		else
		{
			priorityDisplay="Low";
		}

		String reason = request.getParameter("reason");		
		String facilityName = request.getParameter("facilityName");
		
		String bookedOn=df.format(new Date());
		//Hardcode bookingID for demo the functions;
		int bookedBy=10000003;
		String status="Book";
		//Hardcode bookingID for demo the functions;
		int modifiedBy=10000003;
		String modifiedOn=df.format(new Date());
		String comment="";
		
		request.setAttribute("type", type);
		request.setAttribute("emergency", emergency);
		request.setAttribute("priorityDisplay", priorityDisplay);
		request.setAttribute("fromDate", fromDate);
		request.setAttribute("toDate", toDate);
		request.setAttribute("reason", reason);
		request.setAttribute("facilityName", facilityName);
		request.setAttribute("bookedOn", bookedOn);
		request.setAttribute("bookedBy", bookedBy);
		request.setAttribute("status", status);
		request.setAttribute("modifiedBy", modifiedBy);
		request.setAttribute("modifiedOn", modifiedOn);
		request.setAttribute("comment", comment);
		
        HttpSession session = request.getSession();
		
		session.setAttribute("emergency", emergency);		
		session.setAttribute("priority", priority);
		session.setAttribute("fromDate", fromDate);
		session.setAttribute("toDate", toDate);
		session.setAttribute("reason",reason);
		session.setAttribute("facilityName", facilityName);

		RequestDispatcher rd = null;
		rd=request.getRequestDispatcher("/BookingDetails.jsp");	
		rd.forward(request, response);
	}
}
